package com.victor.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.victor.dao.OrderDao;
import com.victor.entity.Express;
import com.victor.entity.JingqubusinessOrder;
import com.victor.entity.JingqubusinessOrderShop;
import com.victor.service.OrderService;

@Service
public class OrderServiceImpl implements OrderService {
	
	@Autowired
	private OrderDao orderDao;
	
	/**
	 * app端添加订单
	 */
	@Override
	public boolean addOrder(JingqubusinessOrder order) {
		return orderDao.addOrder(order);
	}
	
	/**
	 * app端添加购买的商品列表
	 */
	@Override
	public boolean addOrderShop(JingqubusinessOrderShop jingqubusinessOrderShop) {
		return orderDao.addOrderShop(jingqubusinessOrderShop);
	}

	/**
	 * 	根据传入字段查询订单列表
	 */
	@Override
	public List<JingqubusinessOrder> selectOderList(JingqubusinessOrder order) {
		return orderDao.selectOderList(order);
	}
	
	/**
	 * 	根据搜索框查询order列表
	 */
	@Override
	public List<JingqubusinessOrder> selectOderListBySearch(String search) {
		return orderDao.selectOderListBySearch(search);
	}

	/**
	 * 	根据数组，批量删除
	 */
	@Override
	public boolean batchDelete(int[] ids) {
		return orderDao.batchDelete(ids) > 0 ? true : false;
	}

	/**
	 * 获取订单详细列表
	 */
	@Override
	public JingqubusinessOrder selectDeatil(Integer id) {
		return orderDao.selectDeatil(id);
	}

	/**
	 * 	接单
	 * 	向快递信息中添加快递信息
	 */
	@Override
	public boolean receivingOrder(Integer i,String state) {
		return orderDao.receivingOrder(i,state);
	}
	//添加快递信息
	@Override
	public boolean addExpress(Express express) {
		return orderDao.addExpress(express);
	}

	@Override
	public PageInfo<JingqubusinessOrder> selAllByUid(String uid,String state, int page, int row) {
		PageHelper.startPage(page, row);
		List<JingqubusinessOrder> list = orderDao.selAllByUid(uid,state);
		return new PageInfo<>(list, 5);
	}

	@Override
	public JingqubusinessOrder selOrdersById(String oid) {
		return orderDao.selById(oid);
	}

	/**
	 * 根据订单id批量删除订单快递信息
	 */
	@Override
	public boolean batchDeleteExpress(int[] ids) {
		return orderDao.batchDeleteExpress(ids);
	}

	/**
	 * 根据订单id批量删除订单收件人信息
	 */
	@Override
	public boolean batchDeleteAddress(int[] ids) {
		return orderDao.batchDeleteAddress(ids);
	}

	/**
	 * 根据订单id批量删除购买的商品
	 */
	@Override
	public boolean batchDeleteShops(int[] ids) {
		return orderDao.batchDeleteShops(ids);
	}

	@Override
	public boolean updateState(JingqubusinessOrder order) {
		return orderDao.updateOrder(order);
	}

}
